<?php


namespace app\alipay\controller;

use alipagepay\pagepay\buildermodel\AlipayTradePagePayContentBuilder;
use alipagepay\pagepay\service\AlipayTradeService;
use app\common\controller\Checking;
use think\Controller;

class Alipcpay extends Controller
{
    protected $config=[
        //签名方式,默认为RSA2(RSA2048)
        'sign_type' => "RSA2",
        //支付宝公钥
        'alipay_public_key' =>"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArBab5TafIQG7hkZo0hz7tiVkS7zDL1Ri7mNjmjeOw/wgUe/IcwwaWfBxk1zMOZMmVPC3Yzx/AF/PIkCZ5bCRSD11F4JD5KyYQy+KFQKuqNxNjGeGdkEuOd+wPsuHSoDPmCKUJc1ukQehq7j8xK1mb1SHhvPHy93psfmzI8Tsotiqh9f1jHbXciUiG8JVOB5Tu9a6kdKbKZenqbRG5wcK1ggHAm7/VMkaviYATziaxVBuzwLFrfkwRCbbctzaKhRPEgTF9mmanYg4EK3Id/8xBn8REkJJ/P2YgScx6q6UOYhv2QNe/vS1Mk/JQDUwC9wJLY5UZ+ITHKibhmjmHE5rgQIDAQAB",
        //商户私钥
        'merchant_private_key' =>"MIIEpQIBAAKCAQEAuOojDK5M8pd3tKyvXYOhCfv5aQn1SJ0Rx3ilFlC5eadqhyLdV+MT1YO0DRiHhb/lnYxIVQDL1mz36svR11n5ZjNp/Li4W82CuxhVtmMTVRpam7dn4k+eto9lA/3rAJSa6IYtOmiFfp7qvgKoIjNmjTLzU5f85ThRzJYxeRN40VzpXVqG7/RwYcrEeRe7FsznvegXYmg65nzyD2+ES0/hMxXxxEtbB7fJkI0rGlZLd8Z4mv8PK6mnjBDRZFU3NISAjdlo3Yx4cNUmzeONPpt3FQ4q+YO6V+logB6pIJQLcY5MpoPAbDms8gcuIwLbjfEXmsnS1puzJw8JHvZDsnUSiwIDAQABAoIBAFVNpbee3N54o39Uvl18cJjjha5AKshBtUb4z+eYe8e0RL9shQGbPrYb2L7F1xcLbIieg2u7P01+3WuSdQ5McnIEO9ua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1VlBl73fmNyeZYtD+ZCO++OTb/TGDYJ0sCgYB5u6DdLjj2ngNnMfsOk5EHwSyQ7p/UUThBeTrlqYc2BeldQwiHdQUT5VDXaduxEXyjrXNNfh61Wgx35wd344Y9Umyxu/q3B8n2toLwSmv6WdHxqgYh9pMaAW9hR2+cd+3fOUBa1yTRfIjmn5HGj81CByEKDsRPst7WyCICdRG1HwKBgHdXq0iH19cm5qADUjQCzAkkl90GHpjCijqyFkis1rLmQrH9ywCRYIqWBAZ7JwNxI4je5wtnrqM/AiwLzWfA6TKYO5JyX5ECxHWL9FtClC+7D4E+7810eT2EOP4WCcvVQelEzodN3PjeYzWW636H4816hDwcAJ74TSqpyyKC9YTZAoGAbqNPqxxE38CYBHP4ncwAuPeIgqTvZoD0fYIBD4rUrD8CpnzpACOAJ1+iegcJSA5yupxdDW7f3WOYNq95OWE+fe/CcpiKLNHHU6OYEH/7u7wsQs8C5ofpdVopkuweEBm+TjVwJBhKN+4Q4Bz/LMBJ5jqA71CL+cSHJasxDGWPVGY=",
        //编码格式
        'charset' => "UTF-8",
        //支付宝网关
        'gatewayUrl' => "https://openapi-sandbox.dl.alipaydev.com/gateway.do",
//        'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
        //应用ID
        'app_id' => "2021000122668476",
        //异步通知地址
        'notify_url' => WEB_URL."/alipay/alipcpay/alipayNotify",
        //同步跳转
        'return_url' => WEB_URL."",
        //日志路径
        'log_path' => ""
    ];
//    public function pay(){
//        $data['data']=$this->pcpay();
//        Checking::response(200,'ok',$data);
//    }

    public function pay(){
        //商户订单号，商户网站订单系统中唯一订单号，必填
        $out_trade_no = time();
        //订单名称，必填
        $subject = '测试';
        //付款金额，必填
        $total_amount = 0.01;
        //商品描述，可空
        $body = '';
        //构造参数
        $payRequestBuilder = new AlipayTradePagePayContentBuilder();
        $payRequestBuilder->setBody($body);
        $payRequestBuilder->setSubject($subject);
        $payRequestBuilder->setTotalAmount($total_amount);
        $payRequestBuilder->setOutTradeNo($out_trade_no);
        $aop = new AlipayTradeService($this->config);
        /**
         * pagePay 电脑网站支付请求
         * @param $builder 业务参数，使用buildmodel中的对象生成。
         * @param $return_url 同步跳转地址，公网可以访问
         * @param $notify_url 异步通知地址，公网可以访问
         * @return $response 支付宝返回的信息
         */

        $response = $aop->pagePay($payRequestBuilder,$this->config['return_url'],$this->config['notify_url']);
        //输出表单
//        $data=strtr($response, '"', "'");
//        $data=htmlentities($response);
        return $response;
//        Checking::response($data);
//        return $response;
//        var_dump($response);
    }
}